#define PACKET_SIZE 64

typedef BYTE		T0CON_T;
typedef BYTE		T1CON_T;
typedef BYTE		TMR0L_T;
typedef BYTE		TMR0H_T;
typedef BYTE		TMR1L_T;
typedef BYTE		TMR1H_T;
typedef BYTE		ADCON0_T;
typedef BYTE		ADCON1_T;
typedef BYTE		ADCON2_T;
typedef BYTE		PACKET_ID_T;
typedef BYTE		POLL_ID_T;

typedef BYTE		CHUNK_ID;
typedef WORD		CHUNK_VALUE;
typedef BYTE		CHUNK_TIME;

typedef WORD		ADC_VALUE;
typedef BYTE		ADC_STATE;

typedef struct CHUNK_T
{
	CHUNK_ID		id;
	CHUNK_VALUE		value;
	CHUNK_TIME		time;
} CHUNK;

typedef struct CHUNK_ARRAY_T
{
	BYTE	length;
	CHUNK	data[(PACKET_SIZE-sizeof(BYTE)- sizeof(BYTE))/sizeof(CHUNK)];
} CHUNK_ARRAY;

typedef struct ADC_DATA_T
{
	POLL_ID_T	id;
	ADC_STATE	state;
	ADC_VALUE	value;
} ADC_DATA;

typedef struct POLL_T
{
	POLL_ID_T		pollId;
} ADC_POLL;

typedef struct CONFIG_OPTIONS_T
{
	T0CON_T			t0con;
	T1CON_T			t1con;
	TMR0L_T			tmr0l;
	TMR0H_T			tmr0h;
	TMR1L_T			tmr1l;
	TMR1H_T			tmr1h;
	ADCON0_T		adcon0;
	ADCON1_T		adcon1;
	ADCON2_T		adcon2;
} CONFIG_OPTIONS;

typedef union DATA_KOMBI_T
{
	BYTE				bytes[PACKET_SIZE-sizeof(PACKET_ID_T)];
	CHUNK_ARRAY 		chunks;
	CONFIG_OPTIONS		coptions;
	ADC_POLL			poll;
	ADC_DATA			adc;
} DATA_KOMBI_PACKET;

typedef struct HOST_PACKET_T
{
	PACKET_ID_T			id;
	DATA_KOMBI_PACKET	data;
} HOST_PACKET;

typedef enum ADC_STATE_T {START = 1, WAIT = 2, DONE = 3} ADC_STATE;

// ADC_QUERY - read ADC command;
// CONFIG_QUERY - get CONFIG options command;
// CONFIG_CNTRL - set CONFIG options command
typedef enum INPACKET_ID_T {ADC_QUERY = 1, CONFIG_QUERY, CONFIG_CNTRL};

// ADC - answer on ADC_QUERY (depend on SINGLE or PACKET can be one or more values back delivered)
// CONFIG - answer on CONFIG_QUERY
// CONFIGCNTRL - answer on CONFIG_CNTRL command
typedef enum OUTPACKET_ID_T {ADC = 1, CONFIG, CONFIGCNTRL};

// SINGLE - ADC under control of host
// PACKET - ADC will interrupt handled
// UNDEFINED1(2) - reserve
typedef enum ADC_MODE_T {SINGLE = 1, PACKET, UNDEFINED1, UNDEFINED2} ADC_MODE;															// no more than 4 topics (we have 2 bits only)
